<template>
	<view v-if="attendanceList.length === 0">
		<image style="width: 400rpx;height: 400rpx; position: absolute; left: 20%; top:20%"
		    src="https://tj-1305380059.cos.ap-nanjing.myqcloud.com/pic/wujilu.png" mode=""></image>
	</view>
	<view v-else>
		<uni-card v-for="(item,index) in attendanceList" :key="index" :title="item.studentName" :extra="item.className">
			<view v-if="item.mendCardPhoto != null && item.mendCardPhoto != ''">
				<image style="width: 100%;" :src="item.mendCardPhoto" @click="imgClick(item.mendCardPhoto)"></image>
			</view>
			<view>  
				<text>考勤时间：{{ item.accessDate }}</text>  
			</view>  
			<view>
				<text>考勤状态：{{ getType(item.attenceStatus) }}</text>  
			</view>
		</uni-card>
	</view>
</template>

<script>
	import parent from '@/api/modules/parent';
	
	
	export default {
		data() {
			return {
				studentId : uni.getStorageSync("loginId"),
				attendanceList : [],
				tempList: [],
				queryParams: {
					pageSize: 10,
					pageNum: 1,
				},
			}
		},
		created() {
			this.loadData();
		},
		onReachBottom() {
			this.queryParams.pageNum += 1
			parent.getParenChildDorAttendance(this.queryParams).then(res => {
				if(res.code === 200) {
					this.tempList = res.data.list
					this.attendanceList = [...this.attendanceList, ...this.tempList]
				}
			})
			this.tempList = []
			this.$forceUpdate()
		},
		methods: {
			loadData() {
				uni.showLoading({
					mask: true,
					title: '加载中'
				});
				this.queryParams.studentId = this.studentId
				parent.getParenChildDorAttendance(this.queryParams).then(res => {
					uni.hideLoading();
					console.log("学生宿舍考勤：",res)
					this.attendanceList=res.data.list
				}).catch(err => {
					uni.hideLoading();
					console.log("学生宿舍考勤：",err)
				})
			},
			//照片预览
			imgClick(url) {
				uni.previewImage({
					current: 0,
					urls: [url]
				})
			},
			getType(type) {
				if(type === '1') {
					return '正常'
				}else if(type === '2') {
					return '未归寝'
				}else if(type === '3') {
					return '晚归'
				}else if(type === '4') {
					return '请假'
				}else {
					return ''
				}
			}
		}
	}
</script>

<style>
</style>
